package cn.moukou.sbzz.service;

import cn.moukou.sbzz.mapper.EnterpriseMapper;
import cn.moukou.sbzz.mapper.EnterpriseProductMapper;
import cn.moukou.sbzz.pojo.EnterpriseProduct;
import cn.moukou.sbzz.pojo.MetaClass;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EnterpriseProductService {

    @Autowired
    EnterpriseProductMapper enterpriseProductMapper;
    @Autowired
    EnterpriseMapper enterpriseMapper;

    public int pubOneEnterpriseProduct(EnterpriseProduct product) {
        return enterpriseProductMapper.insert(product);
    }

    public List<EnterpriseProduct> getMyEnterpriseProduct(String eid) {
        QueryWrapper<EnterpriseProduct> wrapper = new QueryWrapper<>();
        wrapper.eq("eid", eid);
        return enterpriseProductMapper.selectList(wrapper);
    }

    public List<EnterpriseProduct> getUnpassEnterpriseProduct() {
        QueryWrapper<EnterpriseProduct> wrapper = new QueryWrapper<>();
        wrapper.eq("status", 0);
        return enterpriseProductMapper.selectList(wrapper);
    }

    public List<EnterpriseProduct> getEnterpriseProductList() {
        return enterpriseProductMapper.selectList(null);
    }

    public List<EnterpriseProduct> getProductByFilter(String form, String business, String pool) {
        QueryWrapper<EnterpriseProduct> wrapper = new QueryWrapper<>();
        wrapper.eq("status", 1);
        if(!form.equals("all")) {
            wrapper.eq("form", form);
        }
        if(!business.equals("all")) {
            wrapper.eq("business", business);
            System.out.println(business);
        }
        if(!pool.equals("all")) {
            wrapper.eq("pool", pool);
        }
        return enterpriseProductMapper.selectList(wrapper);
    }

    public EnterpriseProduct getOneProduct(String id) {
        return enterpriseProductMapper.selectById(id);
    }

    public int passEnterpriseProduct(String id) {
        EnterpriseProduct product = enterpriseProductMapper.selectById(id);
        product.setStatus(1);
        return enterpriseProductMapper.updateById(product);
    }

}
